package com.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.system.mapper.T_buyerDOCMapper;
import com.system.pojo.T_buyerDOC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class T_byuerDOCController {
    @Autowired
    private T_buyerDOCMapper t_buyerDOCMapper;

    @RequestMapping("insertks")
    @ResponseBody
    public String insertks(@RequestBody String s) {
        JSONObject object = new JSONObject();
        try {
            System.out.println("输入 : " + s);//接受前端参数
            s = s.replace("[", "");
            s = s.replace("]", "");
            // JSONArray temp=JSONArray.parseArray(s);
            /*JSONObject jsonobject = JSONObject.parseObject(s);
            System.out.println("2322");
            System.out.println(jsonobject);*/
            T_buyerDOC stu = null;
            String title1 = null;
            String title = null;
            String sex = null;
            String data = null;
            String text = null;
            ObjectMapper objectMapper = new ObjectMapper();
            T_buyerDOC t_buyerDOCList = objectMapper.readValue(s, T_buyerDOC.class);
            title1 = t_buyerDOCList.getTSSELLMATERS();
            title = t_buyerDOCList.getTSREQUIRESPECIFICATON();
            sex = t_buyerDOCList.getTSDOUBLE();
            data = t_buyerDOCList.getTSDATE();
            text = t_buyerDOCList.getTSTEXT();
            t_buyerDOCMapper.insertbuyerDOCMapper(title1, title, sex, data, text);
            System.out.println(title1);
            /*try {
                ObjectMapper objectMapper=new ObjectMapper();
                T_buyerDOC studentList=objectMapper.readValue(s, T_buyerDOC.class);
                list=studentList.getDate();
                System.out.println(list);
            } catch (Exception e) {

                e.printStackTrace();
            }*/

            /*String aDDRESS = jsonobject.getString("aDDRESS");
            System.out.println(aDDRESS);
            buyerControllerMapper.deleteBuyer(aDDRESS);*/


            object.put("code", 0);
            object.put("msg", "保存成功");
            return object.toJSONString();

        } catch (Exception e) {
            e.printStackTrace();
            return object.toJSONString();
        }
    }
}
